package com.ncr.travel.appmgr.client.ui.table;

/**
 * A ColumnDescriptor is used to describe details about a column in a LiveFlexTable
 */
public class ColumnDescriptor {
	private String id;
	private String heading;
	private boolean isSortable;

	/**
	 * Constructor
	 * @param id The id used to uniquely identify this column in the LiveFlexTable to which it is attached
	 * @param heading The proper heading to display in the table, when the heading display is enabled
	 * @param isSortable Can this column be sorted?
	 */
	public ColumnDescriptor(String id, String heading, boolean isSortable) {
		this.id = id;
		this.heading = heading;
		this.isSortable = isSortable;
	}

	/**
	 * Constructor; sets heading to null and isSortable to false
	 * @param id The unique identifier for ths column in the LiveFlexTable
	 */
	public ColumnDescriptor(String id) {
		this.id = id;
		heading = null;
		isSortable = false;
	}

	/**
	 * Set the heading of this column
	 * @param heading The heading to use for the column
	 */
	public void setHeading(String heading) {
		this.heading = heading;
		return;
	}

	/**
	 * Set the sortable flag for this column
	 * @param isSortable
	 */
	public void setIsSortable(boolean isSortable) {
		this.isSortable = isSortable;
		return;
	}

	/**
	 * Get the unique id for this column
	 * @return The unique id
	 */
	public String getId() {
		return id;
	}

	/**
	 * Get the proper display heading set for this column
	 * @return The heading string
	 */
	public String getHeading() {
		return heading;
	}

	/**
	 * Get the value of the sortable flag for this column
	 * @return The sortable flag value
	 */
	public boolean getIsSortable() {
		return isSortable;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((heading == null) ? 0 : heading.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + (isSortable ? 1231 : 1237);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ColumnDescriptor other = (ColumnDescriptor) obj;
		if (heading == null) {
			if (other.heading != null)
				return false;
		} else if (!heading.equals(other.heading))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (isSortable != other.isSortable)
			return false;
		return true;
	}

}